package com.tledu.store.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.store.domain.StoreHouse;
import com.tledu.store.service.IStoreHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库房Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/store/house")
public class StoreHouseController extends BaseController
{
    @Autowired
    private IStoreHouseService storeHouseService;

    /**
     * 查询库房列表
     */
    @PreAuthorize("@ss.hasPermi('store:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreHouse storeHouse)
    {
        startPage();
        List<StoreHouse> list = storeHouseService.selectStoreHouseList(storeHouse);
        return getDataTable(list);
    }

    /**
     * 查询未满的库房列表
     */
    @PreAuthorize("@ss.hasPermi('store:house:list')")
    @GetMapping("/unFullList")
    public TableDataInfo unFullList(StoreHouse storeHouse)
    {
        startPage();
        List<StoreHouse> list = storeHouseService.selectUnFullStoreHouseList(storeHouse);
        return getDataTable(list);
    }
    /**
     * 导出库房列表
     */
    @PreAuthorize("@ss.hasPermi('store:house:export')")
    @Log(title = "库房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreHouse storeHouse)
    {
        List<StoreHouse> list = storeHouseService.selectStoreHouseList(storeHouse);
        ExcelUtil<StoreHouse> util = new ExcelUtil<StoreHouse>(StoreHouse.class);
        util.exportExcel(response, list, "库房数据");
    }

    /**
     * 获取库房详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeHouseService.selectStoreHouseById(id));
    }

    /**
     * 新增库房
     */
    @PreAuthorize("@ss.hasPermi('store:house:add')")
    @Log(title = "库房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreHouse storeHouse)
    {
        return toAjax(storeHouseService.insertStoreHouse(storeHouse));
    }

    /**
     * 修改库房
     */
    @PreAuthorize("@ss.hasPermi('store:house:edit')")
    @Log(title = "库房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreHouse storeHouse)
    {
        return toAjax(storeHouseService.updateStoreHouse(storeHouse));
    }

    /**
     * 删除库房
     */
    @PreAuthorize("@ss.hasPermi('store:house:remove')")
    @Log(title = "库房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeHouseService.deleteStoreHouseByIds(ids));
    }

    /**
     * 逻辑删除库房
     */
    @PutMapping("/{ids}")
    public AjaxResult logicRemove(@PathVariable Long[] ids){
        return toAjax(storeHouseService.logicdeleteStoreHouseByIds(ids));
    }
}
